package com.recharge.domain.vo;

import com.google.gson.Gson;
import com.recharge.common.util.DESUtil;
import com.recharge.common.util.http.HttpUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value ="充值单")
public class RechargeDO implements java.io.Serializable {

    /**
     * 商户号
     */
    @ApiModelProperty(value = "下游商家编号")
    private String merchantNo;

    /**
     * 商户号
     */
    @ApiModelProperty(value = "下游商家ID")
    private String merchantId;


    @ApiModelProperty(value = "商户名称")
    private String merchantName;


    @ApiModelProperty(value = "商户密码")
    private String password;

    /**
     * 商品编号
     */
    @ApiModelProperty(value = "商品编号")
    private Integer goodsNo;

    /**
     * 充值号码
     */
    @ApiModelProperty(value = "充值号")
    private String rechargeNumber;

    /**
     * 流水号
     */
    @ApiModelProperty(value = "流水序号")
    private String serialNumber;

    /**
     * 额度
     */
    @ApiModelProperty(value = "面额")
    private Long price;

    /**
     * 提交充值单的时间戳
     */
    @ApiModelProperty(value = "时间戳")
    private Long timestamp;

    /**
     * 商品数量
     */
    private Integer goodsQuantity = 1;

    /**
     * 商品类型
     */
    private Integer goodsType;

    /**
     * 订单号
     */
    private String callbackUrl;

    private String orderNo;

    private String transactionNo;

    private String nodeName;

    /**
     * 0.不是重试 1.重试所有 2.重试当前 3.重试下一个
     */
    private Integer retryStatus = 0;


    /**
     * 重试才用供应通道
     */
    private String providerId;

    /**
     * 重试才用原来的订单Id
     */
    private String orderId;

    /**
     * 版本号
     */
    private String version;

    @Override
    public String toString() {
        return "RechargeDO{" +
                "merchantNo='" + merchantNo + '\'' +
                ", goodsNo='" + goodsNo + '\'' +
                ", rechargeNumber='" + rechargeNumber + '\'' +
                ", serialNumber='" + serialNumber + '\'' +
                ", price=" + price +
                ", timestamp=" + timestamp +
                ", goodsNumber=" + goodsQuantity +
                ", goodsType=" + goodsType +
                ", version='" + version + '\'' +
                '}';
    }

    public static void main(String[] args) {
        for (int i = 0; i < 1; i++){
            Gson gson = new Gson();
            String json = "{\n" +
                    "    \"goodsNo\":10184,\n" +
                    "    \"goodsQuantity\":1,\n" +
                    "    \"goodsType\":1,\n" +
                    "    \"merchantNo\":\"51167943426\",\n" +
                    "    \"price\":10000,\n" +
                    "    \"rechargeNumber\":\"19942358249\",\n" +
                    "    \"serialNumber\":"+System.currentTimeMillis()+",\n" +
                    "    \"timestamp\":"+ System.currentTimeMillis() + ",\n" +
                    "    \"version\":\"1\"\n" +
                    "}";
            EncryptionRechargeDO encryptionRechargeDO = new EncryptionRechargeDO();
            encryptionRechargeDO.setPrivateKey("t7IkHCDgbA1XMiPB7gVTxog5gVfGcU0g");
            encryptionRechargeDO.setEncryptionData(DESUtil.encrypt("t7IkHCDgbA1XMiPB7gVTxog5gVfGcU0g", json));

            String responseData = null;
            try {
                responseData = HttpUtil.post("http://192.168.1.99:9996/app/api/recharge.html", gson.toJson(encryptionRechargeDO), conn -> {
                            conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
                            conn.setRequestProperty("accept", "application/json;charset=utf-8");
                        }
                );
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("回调下游接口返回结果为：" + responseData);
//            System.out.println(DESUtil.decrypt("t7IkHCDgbA1XMiPB7gVTxog5gVfGcU0g", "kkaxPfIPKUC0dmN0j10QZeGoX43yfGi77Fj8BateTpwNnpbS1fjHoQ5oHr7BQzJ4TjD7rOjnbwd99GhZ3ujluOWhj8DHUehLV4rFOdIsChR0+lj9RXSmIseQ4GxiR/XxIMGvhRXCmmeLDMvOW7YjHUE+lJ/tRTIXm39L/tifTU0O5dKAlZKDU7DQ8tLUMZ2SAXai8VA2O+rBuqrtP/lXjCcF4PsyTWav4eYHQJNFWVdW16XxEcbMG6jlCKUwxOBmihAgSxnJT0GRkmclNNJK6/3lMhkCqlzKKAC7fJx47boHN2iXgo+Z7xmWmVTrPykj"));
            System.out.println(gson.toJson(encryptionRechargeDO));
        }
    }
}
